package tests;

import static org.junit.Assert.assertEquals;
import model.components.Component;
import model.components.ComponentDoor;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import utils.Constants;
import controller.FakeNetwork;
import controller.PoolItem;

public class FakeNetworkTest {

	protected FakeNetwork fnet;
	protected ComponentDoor cd;

	@Before
	public void setUp() throws Exception {
		fnet = new FakeNetwork();
		cd = new ComponentDoor("Door 100", Constants.COMPONENT_DOOR_CLOSED);
		cd.setComponentId(10);
		fnet.connectComponent(cd);
	
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void connectComponent() {
		assertEquals((boolean) true, fnet.connectComponent(cd));
	}

	@Test
	public void broadcastItem() {
		assertEquals((boolean) true, fnet.broadcastItem(new PoolItem(Constants.EVENT_DOOR_OPENED, System.currentTimeMillis(), 0)));
	}

	@Test
	public void sendItemToComponent() {
		assertEquals((boolean) true,
				fnet.SendItemToComponentById(new PoolItem(Constants.EVENT_DOOR_OPENED, System.currentTimeMillis(), 0), 10));
		assertEquals((boolean) false,
				fnet.SendItemToComponentById(new PoolItem(Constants.EVENT_DOOR_OPENED, System.currentTimeMillis(), 0), 5));
		assertEquals((boolean) true, fnet.SendItemToComponentByLabel(
				new PoolItem(Constants.EVENT_DOOR_OPENED, System.currentTimeMillis(), 0), "Door 100"));
		assertEquals((boolean) false, fnet.SendItemToComponentByLabel(
				new PoolItem(Constants.EVENT_DOOR_OPENED, System.currentTimeMillis(), 0), "Door 2"));
	}

	@Test
	public void getComponentById() {
		assertEquals((String) "Door 100",
				fnet.getComponentById(10).getComponentLabel());
	}

	@Test
	public void getComponentByLabel() {
		assertEquals((int) 10,
				fnet.getComponentByLabel("Door 100").getComponentId());
	}

}
